package cn.gjxblog.common.model;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

/**
 * @Author guojiaxun
 * @Date 2019/9/12 11:28
 */
@Data
public class PageInfo<T> {
    /**
     * 总记录数
     */
    private long totalCount;

    /**
     * 每页记录数
     */
    private long pageSize;

    /**
     * 总页数
     */
    private long totalPage;

    /**
     * 当前页数
     */
    private long pageNum;

    /**
     * 列表数据
     */
    private List<T> list;


    public PageInfo(IPage<T> page){
        this.list = page.getRecords();
        this.totalCount = page.getTotal();
        this.pageSize = page.getSize();
        this.pageNum = page.getCurrent();
        this.totalPage = page.getPages();
    }

    public PageInfo(long totalCount, long pageSize, long currPage, List<T> list) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.pageNum = currPage;
        this.list = list;
        this.totalPage = (long) Math.ceil((double)totalCount/pageSize);
    }
}
